<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qopenglpaintdevice.cpp -->
  <title>QOpenGLPaintDevice Class | Qt GUI 5.14.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtgui-index.html">Qt GUI</a></td><td ><a href="qtgui-module.html">C++ Classes</a></td><td >QOpenGLPaintDevice</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li>
<li class="level1"><a href="#reimplemented-protected-functions">Reimplemented Protected Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#performance">Performance</a></li>
<li class="level2"><a href="#antialiasing-and-quality">Antialiasing and Quality</a></li>
<li class="level2"><a href="#state-changes">State Changes</a></li>
<li class="level2"><a href="#mixing-qpainter-and-opengl">Mixing QPainter and OpenGL</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QOpenGLPaintDevice Class</h1>
<!-- $$$QOpenGLPaintDevice-brief -->
<p>The QOpenGLPaintDevice class enables painting to an OpenGL context using <a href="qpainter.html">QPainter</a>. <a href="#details">More...</a></p>
<!-- @@@QOpenGLPaintDevice -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QOpenGLPaintDevice&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += gui</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign"> Qt 5.0</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qpaintdevice.html">QPaintDevice</a></td></tr></table></div><p>This class was introduced in Qt 5.0.</p>
<ul>
<li><a href="qopenglpaintdevice-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#QOpenGLPaintDevice-2">QOpenGLPaintDevice</a></b>(int <i>width</i>, int <i>height</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#QOpenGLPaintDevice-1">QOpenGLPaintDevice</a></b>(const QSize &amp;<i>size</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#QOpenGLPaintDevice">QOpenGLPaintDevice</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#dtor.QOpenGLPaintDevice">~QOpenGLPaintDevice</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QOpenGLContext *</td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#context">context</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qreal </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#dotsPerMeterX">dotsPerMeterX</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qreal </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#dotsPerMeterY">dotsPerMeterY</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#ensureActiveTarget">ensureActiveTarget</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#paintFlipped">paintFlipped</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#setDevicePixelRatio">setDevicePixelRatio</a></b>(qreal <i>devicePixelRatio</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#setDotsPerMeterX">setDotsPerMeterX</a></b>(qreal <i>dpmx</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#setDotsPerMeterY">setDotsPerMeterY</a></b>(qreal <i>dpmy</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#setPaintFlipped">setPaintFlipped</a></b>(bool <i>flipped</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#setSize">setSize</a></b>(const QSize &amp;<i>size</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSize </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#size">size</a></b>() const</td></tr>
</table></div>
<a name="reimplemented-public-functions"></a>
<h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual QPaintEngine *</td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#paintEngine">paintEngine</a></b>() const override</td></tr>
</table></div>
<a name="reimplemented-protected-functions"></a>
<h2 id="reimplemented-protected-functions">Reimplemented Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual int </td><td class="memItemRight bottomAlign"><b><a href="qopenglpaintdevice.html#metric">metric</a></b>(QPaintDevice::PaintDeviceMetric <i>metric</i>) const override</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QOpenGLPaintDevice-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The QOpenGLPaintDevice uses the <b>current</b> QOpenGL context to render <a href="qpainter.html">QPainter</a> draw commands. The context is captured upon construction. It requires support for OpenGL (ES) 2.0 or higher.</p>
<a name="performance"></a>
<h3 id="performance">Performance</h3>
<p>The QOpenGLPaintDevice is almost always hardware accelerated and has the potential of being much faster than software rasterization. However, it is more sensitive to state changes, and therefore requires the drawing commands to be carefully ordered to achieve optimal performance.</p>
<a name="antialiasing-and-quality"></a>
<h3 id="antialiasing-and-quality">Antialiasing and Quality</h3>
<p>Antialiasing in the OpenGL paint engine is done using multisampling. Most hardware require significantly more memory to do multisampling and the resulting quality is not on par with the quality of the software paint engine. The OpenGL paint engine's strength lies in its performance, not its visual rendering quality.</p>
<a name="state-changes"></a>
<h3 id="state-changes">State Changes</h3>
<p>When painting to a QOpenGLPaintDevice using <a href="qpainter.html">QPainter</a>, the state of the current OpenGL context will be altered by the paint engine to reflect its needs. Applications should not rely upon the OpenGL state being reset to its original conditions, particularly the current shader program, OpenGL viewport, texture units, and drawing modes.</p>
<a name="mixing-qpainter-and-opengl"></a>
<h3 id="mixing-qpainter-and-opengl">Mixing QPainter and OpenGL</h3>
<p>When intermixing <a href="qpainter.html">QPainter</a> and OpenGL, it is important to notify <a href="qpainter.html">QPainter</a> that the OpenGL state may have been cluttered so it can restore its internal state. This is achieved by calling <a href="qpainter.html#beginNativePainting">QPainter::beginNativePainting</a>() before starting the OpenGL rendering and calling <a href="qpainter.html#endNativePainting">QPainter::endNativePainting</a>() after finishing.</p>
</div>
<p><b>See also </b><a href="qtgui-openglwindow-example.html">OpenGL Window Example</a>.</p>
<!-- @@@QOpenGLPaintDevice -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QOpenGLPaintDevice$$$QOpenGLPaintDeviceintint -->
<h3 class="fn" id="QOpenGLPaintDevice-2"><a name="QOpenGLPaintDevice-2"></a>QOpenGLPaintDevice::<span class="name">QOpenGLPaintDevice</span>(<span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>)</h3>
<p>Constructs a QOpenGLPaintDevice with the given <i>width</i> and <i>height</i>.</p>
<p>The QOpenGLPaintDevice is only valid for the current context.</p>
<p><b>See also </b><a href="qopenglcontext.html#currentContext">QOpenGLContext::currentContext</a>().</p>
<!-- @@@QOpenGLPaintDevice -->
<!-- $$$QOpenGLPaintDevice$$$QOpenGLPaintDeviceconstQSize& -->
<h3 class="fn" id="QOpenGLPaintDevice-1"><a name="QOpenGLPaintDevice-1"></a>QOpenGLPaintDevice::<span class="name">QOpenGLPaintDevice</span>(const <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> &amp;<i>size</i>)</h3>
<p>Constructs a QOpenGLPaintDevice with the given <i>size</i>.</p>
<p>The QOpenGLPaintDevice is only valid for the current context.</p>
<p><b>See also </b><a href="qopenglcontext.html#currentContext">QOpenGLContext::currentContext</a>().</p>
<!-- @@@QOpenGLPaintDevice -->
<!-- $$$QOpenGLPaintDevice[overload1]$$$QOpenGLPaintDevice -->
<h3 class="fn" id="QOpenGLPaintDevice"><a name="QOpenGLPaintDevice"></a>QOpenGLPaintDevice::<span class="name">QOpenGLPaintDevice</span>()</h3>
<p>Constructs a QOpenGLPaintDevice.</p>
<p>The QOpenGLPaintDevice is only valid for the current context.</p>
<p><b>See also </b><a href="qopenglcontext.html#currentContext">QOpenGLContext::currentContext</a>().</p>
<!-- @@@QOpenGLPaintDevice -->
<!-- $$$~QOpenGLPaintDevice[overload1]$$$~QOpenGLPaintDevice -->
<h3 class="fn" id="dtor.QOpenGLPaintDevice"><a name="dtor.QOpenGLPaintDevice"></a><code>[virtual] </code>QOpenGLPaintDevice::<span class="name">~QOpenGLPaintDevice</span>()</h3>
<p>Destroys the <a href="qopenglpaintdevice.html">QOpenGLPaintDevice</a>.</p>
<!-- @@@~QOpenGLPaintDevice -->
<!-- $$$context[overload1]$$$context -->
<h3 class="fn" id="context"><a name="context"></a><span class="type"><a href="qopenglcontext.html">QOpenGLContext</a></span> *QOpenGLPaintDevice::<span class="name">context</span>() const</h3>
<p>Returns the OpenGL context associated with the paint device.</p>
<!-- @@@context -->
<!-- $$$dotsPerMeterX[overload1]$$$dotsPerMeterX -->
<h3 class="fn" id="dotsPerMeterX"><a name="dotsPerMeterX"></a><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> QOpenGLPaintDevice::<span class="name">dotsPerMeterX</span>() const</h3>
<p>Returns the number of pixels per meter horizontally.</p>
<p><b>See also </b><a href="qopenglpaintdevice.html#setDotsPerMeterX">setDotsPerMeterX</a>().</p>
<!-- @@@dotsPerMeterX -->
<!-- $$$dotsPerMeterY[overload1]$$$dotsPerMeterY -->
<h3 class="fn" id="dotsPerMeterY"><a name="dotsPerMeterY"></a><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> QOpenGLPaintDevice::<span class="name">dotsPerMeterY</span>() const</h3>
<p>Returns the number of pixels per meter vertically.</p>
<p><b>See also </b><a href="qopenglpaintdevice.html#setDotsPerMeterY">setDotsPerMeterY</a>().</p>
<!-- @@@dotsPerMeterY -->
<!-- $$$ensureActiveTarget[overload1]$$$ensureActiveTarget -->
<h3 class="fn" id="ensureActiveTarget"><a name="ensureActiveTarget"></a><code>[virtual] </code><span class="type">void</span> QOpenGLPaintDevice::<span class="name">ensureActiveTarget</span>()</h3>
<p>This virtual method is provided as a callback to allow re-binding a target frame buffer object or context when different <a href="qopenglpaintdevice.html">QOpenGLPaintDevice</a> instances are issuing draw calls alternately.</p>
<p><a href="qpainter.html#beginNativePainting">beginNativePainting()</a> will also trigger this method.</p>
<p>The default implementation does nothing.</p>
<!-- @@@ensureActiveTarget -->
<!-- $$$metric[overload1]$$$metricQPaintDevice::PaintDeviceMetric -->
<h3 class="fn" id="metric"><a name="metric"></a><code>[override virtual protected] </code><span class="type">int</span> QOpenGLPaintDevice::<span class="name">metric</span>(<span class="type"><a href="qpaintdevice.html#PaintDeviceMetric-enum">QPaintDevice::PaintDeviceMetric</a></span> <i>metric</i>) const</h3>
<p>Reimplements: <a href="qpaintdevice.html#metric">QPaintDevice::metric</a>(QPaintDevice::PaintDeviceMetric metric) const.</p>
<!-- @@@metric -->
<!-- $$$paintEngine[overload1]$$$paintEngine -->
<h3 class="fn" id="paintEngine"><a name="paintEngine"></a><code>[override virtual] </code><span class="type"><a href="qpaintengine.html">QPaintEngine</a></span> *QOpenGLPaintDevice::<span class="name">paintEngine</span>() const</h3>
<p>Reimplements: <a href="qpaintdevice.html#paintEngine">QPaintDevice::paintEngine</a>() const.</p>
<!-- @@@paintEngine -->
<!-- $$$paintFlipped[overload1]$$$paintFlipped -->
<h3 class="fn" id="paintFlipped"><a name="paintFlipped"></a><span class="type">bool</span> QOpenGLPaintDevice::<span class="name">paintFlipped</span>() const</h3>
<p>Returns <code>true</code> if painting is flipped around the Y-axis.</p>
<p><b>See also </b><a href="qopenglpaintdevice.html#setPaintFlipped">setPaintFlipped</a>().</p>
<!-- @@@paintFlipped -->
<!-- $$$setDevicePixelRatio[overload1]$$$setDevicePixelRatioqreal -->
<h3 class="fn" id="setDevicePixelRatio"><a name="setDevicePixelRatio"></a><span class="type">void</span> QOpenGLPaintDevice::<span class="name">setDevicePixelRatio</span>(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>devicePixelRatio</i>)</h3>
<p>Sets the device pixel ratio for the paint device to <i>devicePixelRatio</i>.</p>
<!-- @@@setDevicePixelRatio -->
<!-- $$$setDotsPerMeterX[overload1]$$$setDotsPerMeterXqreal -->
<h3 class="fn" id="setDotsPerMeterX"><a name="setDotsPerMeterX"></a><span class="type">void</span> QOpenGLPaintDevice::<span class="name">setDotsPerMeterX</span>(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>dpmx</i>)</h3>
<p>Sets the number of pixels per meter horizontally to <i>dpmx</i>.</p>
<p><b>See also </b><a href="qopenglpaintdevice.html#dotsPerMeterX">dotsPerMeterX</a>().</p>
<!-- @@@setDotsPerMeterX -->
<!-- $$$setDotsPerMeterY[overload1]$$$setDotsPerMeterYqreal -->
<h3 class="fn" id="setDotsPerMeterY"><a name="setDotsPerMeterY"></a><span class="type">void</span> QOpenGLPaintDevice::<span class="name">setDotsPerMeterY</span>(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>dpmy</i>)</h3>
<p>Sets the number of pixels per meter vertically to <i>dpmy</i>.</p>
<p><b>See also </b><a href="qopenglpaintdevice.html#dotsPerMeterY">dotsPerMeterY</a>().</p>
<!-- @@@setDotsPerMeterY -->
<!-- $$$setPaintFlipped[overload1]$$$setPaintFlippedbool -->
<h3 class="fn" id="setPaintFlipped"><a name="setPaintFlipped"></a><span class="type">void</span> QOpenGLPaintDevice::<span class="name">setPaintFlipped</span>(<span class="type">bool</span> <i>flipped</i>)</h3>
<p>Sets whether painting should be flipped around the Y-axis or not to <i>flipped</i>.</p>
<p><b>See also </b><a href="qopenglpaintdevice.html#paintFlipped">paintFlipped</a>().</p>
<!-- @@@setPaintFlipped -->
<!-- $$$setSize[overload1]$$$setSizeconstQSize& -->
<h3 class="fn" id="setSize"><a name="setSize"></a><span class="type">void</span> QOpenGLPaintDevice::<span class="name">setSize</span>(const <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> &amp;<i>size</i>)</h3>
<p>Sets the pixel size of the paint device to <i>size</i>.</p>
<p><b>See also </b><a href="qopenglpaintdevice.html#size">size</a>().</p>
<!-- @@@setSize -->
<!-- $$$size[overload1]$$$size -->
<h3 class="fn" id="size"><a name="size"></a><span class="type"><a href="../qtcore/qsize.html">QSize</a></span> QOpenGLPaintDevice::<span class="name">size</span>() const</h3>
<p>Returns the pixel size of the paint device.</p>
<p><b>See also </b><a href="qopenglpaintdevice.html#setSize">setSize</a>().</p>
<!-- @@@size -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
